import {defHttp} from '/@/utils/http/axios';
import { useMessage } from "/@/hooks/web/useMessage";

const { createConfirm } = useMessage();

enum Api {
  list = '/esidcard/card/list',
  save='/esidcard/card/add',
  edit='/esidcard/card/edit',
  syncCardInfo='/esidcard/card/syncCardInfo',
  deleteOne = '/esidcard/card/delete',
  unbind = '/esidcard/card/unbind',
  bindParent = '/esidcard/card/bindParent',
  unbindParents = '/esidcard/card/unbindParents',
  deleteBatch = '/esidcard/card/deleteBatch',
  importExcel = '/esidcard/card/importExcel',
  exportXls = '/esidcard/card/exportXls',
}
/**
 * 导出api
 * @param params
 */
export const getExportUrl = Api.exportXls;
/**
 * 导入api
 */
export const getImportUrl = Api.importExcel;
/**
 * 列表接口
 * @param params
 */
export const list = (params) =>
  defHttp.get({url: Api.list, params});

/**
 * 删除单个
 */
export const deleteOne = (params,handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '删除学生证',
    content: '是否确认删除当前学生证',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.get({url: Api.deleteOne, params}, {joinParamsToUrl: true}).then(() => {
        handleSuccess();
      });
    }
  });
}
/**
 * 解绑学生
 */
export const unbind = (params,handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '学生解绑',
    content: '是否确认解绑当前学生',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.get({url: Api.unbind, params}, {joinParamsToUrl: true}).then(() => {
        handleSuccess();
      });
    }
  });
}

/**
 * 解绑所有家长
 * @param params
 */
export const unbindParents = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '家长解绑',
    content: '是否解绑所有家长',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.post({url: Api.unbindParents, data: params}, {joinParamsToUrl: true}).then(() => {
        handleSuccess();
      });
    }
  });
}
/**
 * 保存或者更新
 * @param params
 */
export const saveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({url: url, params});
}

/**
 * 学生一健录入
 * @param params
 */
export const syncCardInfo = (params) =>
  defHttp.post({url: Api.syncCardInfo, params});

/**
 * 绑定家长
 * @param params
 */
export const bindParent = (params) =>
  defHttp.post({url: Api.bindParent, params});

